/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.agh.air.bpel2bpmn.comparator.impl;

import org.agh.air.bpel2bpmn.comparator.AbstractComparator;
import org.agh.air.bpel2bpmn.exception.PatternNotFoundException;
import org.w3c.dom.Node;

/**
 *
 * @author paletz
 */
public class DeferredChoiceComparator extends AbstractComparator {

    /* <sequence>
    <pick name="Gateway-13607" createInstance="no">
    <onMessage partnerLink="" portType="" operation="" variable="">
    <invoke name="Task-13610" partnerLink="" portType="" operation=""
    inputVariable="" outputVariable=""/>
    </onMessage>
    <onAlarm until="2005:01:01 00:00:00">
    <invoke name="Task-13616" partnerLink="" portType="" operation=""
    inputVariable="" outputVariable=""/>
    </onAlarm>
    </pick>
    </sequence>
     */
    @Override
    public String compare(Node node) throws PatternNotFoundException {
        
        if (node.getNodeName().equals(PICK) && node.hasChildNodes() && node.getChildNodes().getLength() == 2) {            
            if (getFirstChild(node).getNodeName().startsWith(ON_MESSAGE) && getSecondChild(node).getNodeName().startsWith(ON_ALARM)) {
                
                return "deferred_choice" + LTMP +  getFirstChild(node).getNodeName() + "." + getSecondChild(node).getNodeName() + RTMP;
            }
            
        }
        
        
        throw new PatternNotFoundException();
    }
}
